package com.st.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jwt.util.JsonUtils;
import com.st.entity.Attractions;
import com.st.entity.Content;
import com.st.entity.Result;
import com.st.entity.ScenicDetail;
import com.st.service.IContentService;
import com.st.service.IScenicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/scenic")
public class ScenicController {
    @Autowired
    private IScenicService iScenicService;

    @RequestMapping("/getScenicDetailByAid")
    public ScenicDetail getScenicDetailByAid(@RequestParam("attractionsId")Integer attractionsId){
        return iScenicService.findScenicDetailByAid(attractionsId);
    }
    @RequestMapping("audit")
    public Result audit(Integer attractionsId){
        Result audit = iScenicService.audit(attractionsId);
        return audit;
    }
    @RequestMapping("/getScenicById")
    public ScenicDetail getScenicById(@RequestParam("attractionsId")Integer attractionsId){
        return iScenicService.findScenicById(attractionsId);
    }

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private IContentService iContentService;
    //保存轮播图
    @RequestMapping("/saveContent")
    public Result content(){
        return iContentService.content();
    }
    //查找热门景点
    @RequestMapping("/getHot")
    public List<Attractions> getHot(){
        String hot = stringRedisTemplate.boundValueOps("hot").get();
        List<Attractions> attractions = (List<Attractions>) JsonUtils.toBean(hot, Attractions.class);
        return attractions;
    }
    //查找首页轮播图
    @RequestMapping("/getContent")
    public List<Content> getContent(){
        String lunbotu = stringRedisTemplate.boundValueOps("lunbotu").get();
        List<Content> contents = (List<Content>) JsonUtils.toBean(lunbotu, Content.class);
        return contents;
    }
}
